import ACCESS_ENUM from "./accessEnum";

 //needAccess指要访问该菜单栏需要什么权限，比如访问管理员界面需要管理员权限
//公共判断权限功能
const checkAccess=(loginUser:any, needAccess:string=ACCESS_ENUM.NOT_LOGIN)=>{
  const loginUserAccess = loginUser?.userRole ?? ACCESS_ENUM.NOT_LOGIN;
  
  if(needAccess === ACCESS_ENUM.NOT_LOGIN){
     return true;
   }   

  if(needAccess === ACCESS_ENUM.USER){
    if(loginUserAccess === ACCESS_ENUM.NOT_LOGIN){
        return false;
    }
  }
  
  if(needAccess === ACCESS_ENUM.ADMIN){
    if(loginUserAccess !== ACCESS_ENUM.ADMIN){
        return false;
    }
  }
    return true;
};

export default checkAccess;